package com.itheima.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.domain.Page;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T>{
	protected T model;
	protected int page;
	protected int rows;
	
	//压栈
	protected  void pushvaluestack(Page<T> pages){
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("total", pages.getTotalElements());
		//System.out.println("total 内容=--------------  "+pages.getTotalElements());
		map.put("rows", pages.getContent());
		//System.out.println("rows 内容=--------------  "+pages.getContent());
		ActionContext.getContext().getValueStack().push(map);
	}
	
	
	
	public BaseAction() {
		
		Type superclass = this.getClass().getGenericSuperclass();
		ParameterizedType pt=(ParameterizedType)superclass;
		Class<T> cla=(Class<T>)pt.getActualTypeArguments()[0];
		try {
			model=cla.newInstance();
			//System.out.println("----------------------------------------------"+model.getClass().getName());
			if(model.getClass().getName().equals("FixedArea")){
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("构建对象失败。。。。");
		} 
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	@Override
	public T getModel() {
		// TODO Auto-generated method stub
		return model;
	}

}
